package com.yyt.module_main.act;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.yyt.libsrc.bean.ShowWithdrawDetailBean;
import com.yyt.libsrc.bean.WithdrawStateBean;
import com.yyt.libsrc.conf.Consts;
import com.yyt.libsrc.net.JavaParamsBuilder;
import com.yyt.libsrc.net.NetUtil;
import com.yyt.libsrc.net.SuccessCallback;
import com.yyt.libsrc.router.RouteTable;
import com.yyt.module_main.R;
import com.yyt.module_main.databinding.ActivityAuditStateBinding;
import com.yyt.module_main.databinding.ItemAuditStateBinding;
import com.yyt.module_main.vm.AuditStateVM;

import java.util.ArrayList;
import java.util.List;

import top.lixb.libcommon.base.ItemHolder;
import top.lixb.libcommon.base.RefreshableActivity;
import top.lixb.libcommon.base.SimpleBindingAdapter;

@Route(path = RouteTable.main_audit_state)
public class AuditStateActivity extends RefreshableActivity<ActivityAuditStateBinding> {

    private AuditStateVM mVm;
    private SimpleBindingAdapter<WithdrawStateBean, ItemAuditStateBinding> mAdapter;

    @Override
    protected void init() {
        mVm = new AuditStateVM();
        mRefreshContentBinding.setVm(mVm);
        setTitle("审核状态");
        mRefreshContentBinding.rv.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new SimpleBindingAdapter<WithdrawStateBean, ItemAuditStateBinding>(R.layout.item_audit_state) {

            @Override
            public void bind(@NonNull ItemHolder<ItemAuditStateBinding> holder, WithdrawStateBean bean) {
                int adapterPosition = holder.getAdapterPosition();
                if (adapterPosition == 0) {
                    holder.getBinding().lineTop.setVisibility(View.INVISIBLE);
                    holder.getBinding().ivState.setImageResource(R.mipmap.ic_exam_cur);
                    holder.getBinding().tvStateTitle.setTextColor(Color.rgb(0x33, 0x33, 0x33));
                } else {
                    holder.getBinding().lineTop.setVisibility(View.VISIBLE);
                    holder.getBinding().ivState.setImageResource(R.mipmap.ic_exam);
                    holder.getBinding().tvStateTitle.setTextColor(Color.rgb(0x66, 0x66, 0x66));
                }

                holder.getBinding().tvStateTitle.setText(bean.title);
                holder.getBinding().tvStateDesc.setText(bean.desc);
            }
        };
        mRefreshContentBinding.rv.setAdapter(mAdapter);
    }

    @Override
    protected int initRefreshLayout() {
        return R.layout.activity_audit_state;
    }

    @Override
    protected void getData(boolean refresh) {
        String reqSn = "";
        if (getIntent() != null && getIntent().getExtras() != null) {
            reqSn = getIntent().getExtras().getString("reqSn");
        }
        NetUtil.sellerPost(new JavaParamsBuilder()
                .addCmd(Consts.CMD.showDetails)
                .addP("req_sn", reqSn)
                .build(), new SuccessCallback<ShowWithdrawDetailBean>() {
            @Override
            public void onSuccess(ShowWithdrawDetailBean bean) {
                List<WithdrawStateBean> list = new ArrayList<>();
                WithdrawStateBean bean1 = new WithdrawStateBean();
                if (bean.data.status == 1) { //订单提交

                } else if (bean.data.status == 2) {
                    bean1.title = "您的款项已到账";
                    bean1.desc = "订单已完成";
                    list.add(bean1);

                    WithdrawStateBean bean2 = new WithdrawStateBean();
                    bean2.title = "审核已经通过";
                    list.add(bean2);
                } else if (bean.data.status == 3) {
                    bean1.title = "打款失败";
                    list.add(bean1);
                }


                WithdrawStateBean bean3 = new WithdrawStateBean();
                bean3.title = "您的订单已确认";
                bean3.desc = "预计24小时内审核您的订单\n" +
                        "请耐心等待";
                WithdrawStateBean bean4 = new WithdrawStateBean();
                bean4.title = "您的订单已经提交";
                bean4.desc = "请耐心等待";


                list.add(bean3);
                list.add(bean4);

                mAdapter.setNewData(list);
            }

            @Override
            public void onComplete() {
                super.onComplete();
                finishGetData();
            }
        });
    }
}
